﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class parameter : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DBaccess db = new DBaccess();
            DataSet ds1 = new DataSet();
            DataSet ds2 = new DataSet();
            DataSet ds3 = new DataSet();
            DataSet ds4 = new DataSet();
            DataSet ds5 = new DataSet();
            ds1 = db.GetDataSet("select * from mr_parameter where pname = 'download'");
            TextBoxDownload.Text = double.Parse(ds1.Tables[0].Rows[0]["value"].ToString()) * 100 + "%";
            ds2 = db.GetDataSet("select * from mr_parameter where pname = 'preference'");
            TextBoxPreference.Text = double.Parse(ds2.Tables[0].Rows[0]["value"].ToString()) * 100 + "%";
            ds3 = db.GetDataSet("select * from mr_parameter where pname = 'time'");
            TextBoxTime.Text = double.Parse(ds3.Tables[0].Rows[0]["value"].ToString()) * 100 + "%";
            ds4 = db.GetDataSet("select * from mr_parameter where pname = 'difficulty'");
            TextBoxGPA.Text = double.Parse(ds4.Tables[0].Rows[0]["value"].ToString()) * 100  + "%";
            ds5 = db.GetDataSet("select * from mr_parameter where pname = 'GPAperscore'");
            TextBoxDiff.Text = ds5.Tables[0].Rows[0]["value"].ToString();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (double.Parse(TextBoxDownload.Text) + double.Parse(TextBoxPreference.Text) + double.Parse(TextBoxTime.Text) + double.Parse(TextBoxGPA.Text) == 1)
        {
            DBaccess db = new DBaccess();
            String[] sql = new String[5];
            sql[0] = "update mr_resource set value = '" + TextBoxDownload.Text + "' where pname = 'download'";
            sql[1] = "update mr_resource set value = '" + TextBoxPreference.Text + "' where panme = 'preference'";
            sql[2] = "update mr_resource set value = '" + TextBoxTime.Text + "' where panme = 'time'";
            sql[3] = "update mr_resource set value = '" + TextBoxGPA.Text + "' where panme = 'difficulty'";
            sql[4] = "update mr_resource set value = '" + TextBoxDiff.Text + "' where panme = 'GPAperscore'";
            db.ExecTranscation(sql);
            Response.Write("<script>alert('modify成功!');</script>");
        }
        else
            Response.Write("<script>alert('请确保各权值总和为100%');</script>");
    }
}